/*
 * Copyright (c) 2011 Anthony Vandikas
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 
 * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 
 * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 
 * is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#pragma once

/**
 * Contains information regarding a sign-out action.
 */
struct Entry
{
public:
	/**
	 * Constructs a default entry.
	 */
	Entry();

	/**
	 * Constructs an entry at a given date/time, with the specified Student and Item.
	 * 
	 * @param dateTime The date and time at which this entry was recorded.
	 * @param student The student who recorded this entry.
	 * @param item The item which which was signed out by the student.
	 */
	Entry(const QDateTime &dateTime, const Student &student, const Item &item);

	/**
	 * Gets the date this entry was recorded.
	 */
	QDate getDate() const;

	/**
	 * Gets the time this entry was recorded.
	 */
	QTime getTime() const;

	/**
	 * Gets the date and time this entry was recorded.
	 */
	QDateTime getDateTime() const;

	/**
	 * Gets the student who recorded this entry.
	 */
	Student getStudent() const;

	/**
	 * Gets the item which was signed out by the student.
	 */
	Item getItem() const;

	/**
	 * Sets the date and time at which this entry was recorded.
	 *
	 * @param value The value to store.
	 */
	void setDateTime(const QDateTime &value);

	/**
	 * Sets the student who recorded this entry.
	 *
	 * @param value The value to store.
	 */
	void setStudent(const Student &value);

	/**
	 * Sets the item the student signed out.
	 *
	 * @param value The value to store.
	 */
	void setItem(const Item &value);

	/**
	 * Creates a string representation of this entry.
	 */
	QString toString() const;

	/**
	 * Determines if this and another entry are equal.
	 *
	 * @param value The entry to compare against.
	 */
	bool operator ==(const Entry &value) const;

	/**
	 * Determines if this and another entry are not equal.
	 *
	 * @param value The entry to compare against.
	 */
	bool operator !=(const Entry &value) const;

private:
	QDateTime dateTime;
	Student student;
	Item item;
};

/**
 * Writes an entry to a stream.
 *
 * This method works by writing the individual properties
 * (dateTime, student, item) one at a time, so it is possible
 * to do something like this:
 *
 * Entry entry = ...;
 * myStream << entry;
 * 
 * QDateTime dateTime;
 * myStream >> dateTime;
 *
 * @param stream The stream to write to.
 * @param entry The entry to write.
 */
QDataStream &operator <<(QDataStream &stream, const Entry &entry);

/**
 * Writes an entry to a stream.
 *
 * Data is obtained by reading the individual properties
 * (dateTime, student, item) one at a time.
 *
 * @param stream The stream to read from.
 * @param entry The entry in which the read data is stored.
 */
QDataStream &operator >>(QDataStream &stream, Entry &entry);
